using Godot;
using System;

public partial class NRemoteHurt : NHurt
{
	[Export] public string mRemoteChaPath = "";
	[Export] public float mMoveSpeed = 500;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		NCharacter cha = GetNodeOrNull<NCharacter>(mSelfChaPath);
		NCharacter enemy = GetNodeOrNull<NCharacter>(mRemoteChaPath);
		if (enemy != null)
		{
			if (GlobalPosition.DistanceTo(enemy.GlobalPosition) < mMoveSpeed * (float)delta)
			{
				cha.CurSkill.calHurt(cha, enemy);
				GD.Print(enemy.Name, ":", enemy.mData.mLife);
				CHelp.free(this);
			}
			else
			{
				Vector2 dir = (enemy.GlobalPosition - GlobalPosition).Normalized();
				GlobalPosition += dir * mMoveSpeed * (float)delta;
			}
		}
		else
		{
			CHelp.free(this);
		}

	}
}
